// components/textEditor/textEditor.js
var util = require('../../utils/util.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    avatarUrl: {
      type: String,
      value: '../../resources/index_' + util.random(1,6) + '.png',
      observer: function (newVal, oldVal, changedPath) {
        _this = this
        if (newVal.trim() != oldVal.trim()) {
        }
      }
    },
    value: {
      type: String,
      value: ''
    },
    showPre: {
      type: String,
      value: '1'
    },
    title: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {
        if (newVal.trim() != oldVal.trim()) {
        }
      }
    },
    typeStr: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {
        if (newVal.trim() != oldVal.trim()) {
        }
      }
    },
    tips: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {
        if (newVal.trim() != oldVal.trim()) {
        }
      }
    },
    placeholder: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {
        if (newVal.trim() != oldVal.trim()) {
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    value: '',
  },
  /**
   * 组件的方法列表
   */
  methods: {
    wxFormatCheck: function(t) {
      var matched = false
      if (t && (t = t.trim()), t) {
        if (/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/.test(t)) matched = true;
      }
      return matched
    },
    bindinput: function (e) {
      this.data.value = e.detail.value
    },
    nextBtnClick: function (e) {
      console.log(this.properties.typeStr)
      console.log(this.properties.typeStr)

      if (this.data.value.trim() == '') {
        wx.showToast({
          title: this.properties.title,
          icon: 'none'
        })
        return
      }
      // if (this.properties.typeStr == '微信号' && !this.wxFormatCheck(this.data.value)) {
      //   wx.showToast({
      //     title: '请填写正确的微信号',
      //     icon: 'none'
      //   })
      //   return
      // }
      this.triggerEvent('textFinishedHandle', { 'content': this.data.value}, {})
    },
    skipBtnClick: function (e) {
      this.triggerEvent('skipHandle', {}, {})
    },
    goPrePage: function (e) {
      this.triggerEvent('goPre', {}, {})
    },
  }
})
